﻿@{
    ViewBag.Title = "openEditMenu";
    Layout = "~/Views/Shared/_AdminLayout.cshtml";
}
@model Menu
@{
    Menu ItemMenu = ViewBag.MenuInfo != null ? (Menu)ViewBag.MenuInfo : new Menu();        
}

<form id="fMenu" action="" method="post">

@Html.Hidden("MenuID", ItemMenu.MenuID)
<div>
    <div class="cl_Row">
        <div class="cl_Title">Menu name</div>
        <div class="cl_Input">
            @Html.TextBox("MenuName", ItemMenu.MenuName)
        </div>
    </div>

     <div class="cl_Row">
        <div class="cl_Title">Menu Parent</div>
        <div class="cl_Input">
            @Html.DropDownList("ParentID", ViewBag.lstMenuParent != null ? (List<SelectListItem>)ViewBag.lstMenuParent : new List<SelectListItem>(), new { style = "width:100px" })           
        </div>
    </div>

     <div class="cl_Row">
        <div class="cl_Title">Links</div>
        <div class="cl_Input">
            @Html.DropDownList("SelMenuUrl", ViewBag.lstBaiViet != null ? (List<SelectListItem>)ViewBag.lstBaiViet : new List<SelectListItem>(), new { style = "width:100px", onchange = "SelMenuUrlChange();" })                                   
        </div>
    </div>


     <div class="cl_Row">
        <div class="cl_Title">Links </div>
        <div class="cl_Input">            
            @Html.TextBox("MenuUrl", ItemMenu.MenuUrl)
        </div>
    </div>
    <div class="cl_Row">
        <div class="cl_Title">Type view</div>
        <div class="cl_Input">
            <select id="SiteView" name="SiteView">
                <option value="@menuViewSite.User">User site</option>
                <option value="@menuViewSite.Admin" @(ItemMenu.SiteView == menuViewSite.Admin ? "selected='selected'" : "" )>Admin site</option>
            </select>
        </div>
    </div>

</div>
</form>


@section Toolbar {
@*<a class="btn_boder btn_new" onclick="openNew()">New</a>*@
<a class="btn_boder btn_save" onclick="onSave()">Save</a>
<a class="btn_boder btn_cancel" onclick="onCancel()" >Cancel</a>
@*<a class="btn_boder btn_delete">Delete</a>*@

}


@section HeaderContent{
    <script type="text/javascript">

        function SelMenuUrlChange() {
            var menuUrl = "/du-an/" + $("#SelMenuUrl").val();
            $("#MenuUrl").val(menuUrl);
        }

        function openNew() {
            window.location.assign("/menu/openEditMenu");
        }

        function onCancel() {
            window.location.assign("/menu/ManagerMenu");
        }

        function openEdit() {
            var lstSelected = "";
            $("td.classFist div.checked").each(function () {
                //$(this).attr('name');
                lstSelected = lstSelected + ";" + $(this).attr("id");
            });

            var lsCount = lstSelected.length;

            if (lsCount > 37) {
                cusAlert("Bạn chỉ cập nhật thông tin 1 menu/ 1 lần...");
            }
            else if (lsCount <= 0) {
                cusAlert("Vui lòng chọn 1 menu để cập nhật");
            }
            else {

                var _DisCode = lstSelected.split(";");
                itemcode = _DisCode[1];

                var dt = new Date();
                var href = "/Building/openEdit?id=" + itemcode + "&dt=" + dt.getTime();
                window.location.assign(href);
            }

        }
        
        function onSave() {            

            $.ajax({ type: 'POST', url: '/menu/InsertMenu', data: $('#fMenu').serialize(), success: function (response) {

                switch (response) {
                    case "00": // save fail                                          
                        cusAlert("Lưu menu thành công");
                        onCancel();
                        break;

                    case "01": // ko the tao user, save sm_user_store loi                                           
                        cusAlert("Quá trình lưu gặp lỗi vui lòng liên hệ quản trị viên");
                        break;

                    default:
                        break;
                }
            }
            });

        }

    </script>
}